import type { ConsultIllness, PartailConsult } from '@/types/consult.d'
import { ref } from 'vue'
import { defineStore } from 'pinia'
import type { ConsultType } from '@/enum'

export const useConsultStore = defineStore(
  'cp-consult',
  () => {
    // 1. 问诊记录对象
    const consult = ref<PartailConsult>({})
    // 2. 修改问诊类型
    const setType = (type: ConsultType) => (consult.value.type = type)
    // 3. 修改急速问诊类型
    const setIllnessType = (type: 0 | 1) => (consult.value.illnessType = type)
    // 4. 修改科室
    const setDep = (depId: string) => (consult.value.depId = depId)
    // 5. 修改并且描述相关信息
    const setIllness = (illness: ConsultIllness) => {
      consult.value.illnessDesc = illness.illnessDesc
      consult.value.illnessTime = illness.illnessTime
      consult.value.consultFlag = illness.consultFlag
      consult.value.pictures = illness.pictures
    }
    // 6. 修改患者信息
    const setPatient = (id: string) => (consult.value.patientId = id)
    // 7. 修改优惠券信息
    // 优惠券有可能没有
    const setCoupon = (id?: string) => (consult.value.couponId = id)
    // 8. 清空问诊记录
    const clear = () => (consult.value = {})

    return {
      consult,
      setType,
      setIllnessType,
      setDep,
      setIllness,
      setPatient,
      setCoupon,
      clear
    }
  },
  {
    // 持久化
    persist: true
  }
)
